package com.lottery.ruok.lottrey.adapter;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lottery.ruok.lottrey.R;
import com.lottery.ruok.lottrey.retrofitModule.response.MemberSummaryResponse;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by ASUS on 2017/10/18.
 */

public class SummaryAdapter extends BaseAdapter {
    private MemberSummaryResponse memberSummaryResponse;
    private Context context;

    public SummaryAdapter(MemberSummaryResponse memberSummaryResponse, Context context) {
        this.memberSummaryResponse = memberSummaryResponse;
        this.context = context;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        ViewHolder holder;
        if (view != null) {
            holder = (ViewHolder) view.getTag();
        } else {
            view = LayoutInflater.from(context).inflate(R.layout.summary_item, parent, false);
            holder = new ViewHolder(view);
            view.setTag(holder);
        }

        holder.category1.setText(memberSummaryResponse.getList().get(position).getName());
        holder.notes.setText(memberSummaryResponse.getList().get(position).getNote_count() + "");
        holder.money.setText(memberSummaryResponse.getList().get(position).getAmount());
        if(!TextUtils.isEmpty(memberSummaryResponse.getList().get(position).getProfit()) && Float.parseFloat(memberSummaryResponse.getList().get(position).getProfit()) > 0){
            holder.profit.setTextColor(Color.parseColor("#e35010"));
        } else {
            holder.profit.setTextColor(Color.parseColor("#3f3f3f"));
        }
        holder.profit.setText(memberSummaryResponse.getList().get(position).getProfit());

        return view;
    }

    @Override
    public int getCount() {
        if(memberSummaryResponse == null || memberSummaryResponse.getList() == null){
            return 0;
        }
        return memberSummaryResponse.getList().size();
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    static class ViewHolder {
        @BindView(R.id.category1)
        TextView category1;
        @BindView(R.id.notes)
        TextView notes;
        @BindView(R.id.money)
        TextView money;
        @BindView(R.id.profit)
        TextView profit;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
